<template>
  <view class="template-about tn-safe-area-inset-bottom">
    <!-- 顶部自定义导航 -->
    <!-- <tn-nav-bar fixed alpha customBack>
      <view slot="back" class='tn-custom-nav-bar__back'
        @click="goBack">
        <text class='icon tn-icon-left'></text>
        <text class='icon tn-icon-home-capsule-fill'></text>
      </view>
    </tn-nav-bar> -->
    
	<uni-sign-in ref="signIn"></uni-sign-in>
    <view class="top-backgroup">
      <image src='https://resource.tuniaokj.com/images/swiper/summer.jpg' mode='widthFix' class='backgroud-image'></image>
    </view>
    
    <view class="tnwave waveAnimation">
      <view class="waveWrapperInner bgTop">
        <view class="wave waveTop" style="background-image: url('https://resource.tuniaokj.com/images/wave/wave-2.png')"></view>
      </view>
      <view class="waveWrapperInner bgMiddle">
        <view class="wave waveMiddle" style="background-image: url('https://resource.tuniaokj.com/images/wave/wave-2.png')"></view>
      </view>
      <view class="waveWrapperInner bgBottom">
        <view class="wave waveBottom" style="background-image: url('https://resource.tuniaokj.com/images/wave/wave-1.png')"></view>
      </view>
    </view>
    
    <view class="about__wrap"  >
      <!-- 头像用户信息 -->
      <view class="user-info__container tn-flex tn-flex-direction-column tn-flex-col-center tn-flex-row-center" @click.capture="toUserInfo">
        <view class="user-info__avatar tn-bg-grey--light tn-flex tn-flex-col-center tn-flex-row-center">
         <cloud-image width="150rpx" height="150rpx" v-if="hasLogin&&userInfo.avatar_file&&userInfo.avatar_file.url" :src="userInfo.avatar_file.url"></cloud-image>
         <view v-else class="defaultAvatarUrl">
         	<uni-icons color="#ffffff" size="50" type="person-filled" />
         </view>
        </view>
        <view class="user-info__nick-name">
			<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
			<text class="uer-name" v-else>{{$t('mine.notLogged')}}</text>
		</view>
      </view>
      

      
      <!-- 消息&数据 -->
     <view class="tn-shadow-warp" style="margin-top: 100rpx;background-color: rgba(255,255,255,1);">
        <view class="tn-flex">
          <view class="tn-flex-1 tn-padding-sm tn-margin-xs">
            <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
              <view class="">
                <view class="tn-text-xxl tn-color-orange">{{userData.days}}天</view>
              </view>
              <view class="tn-margin-top-xs tn-color-gray tn-text-df tn-text-center">
                <text class="tn-icon-lucky-money"></text>
                <text class="tn-padding-left-xs">已学习</text>
              </view>
            </view>
          </view>
         
          <view class="tn-flex-1 tn-padding-sm tn-margin-xs">
            <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
              <view class="">
                <view class="tn-text-xxl tn-color-red">{{userData.words}}个</view>
              </view>
              <view class="tn-margin-top-xs tn-color-gray tn-text-df tn-text-center">
                <text class="tn-icon-coupon"></text>
                <text class="tn-padding-left-xs">学单词</text>
              </view>
            </view>
          </view>
		  <view class="tn-flex-1 tn-padding-sm tn-margin-xs">
		    <view class="tn-flex tn-flex-direction-column tn-flex-row-center tn-flex-col-center">
		      <view class="">
		        <view class="tn-text-xxl tn-color-blue">{{userData.score}}</view>
		      </view>
		      <view class="tn-margin-top-xs tn-color-gray tn-text-df tn-text-center">
		        <text class="tn-icon-sprout"></text>
		        <text class="tn-padding-left-xs">积分</text>
		      </view>
		    </view>
		  </view>
        </view>
      </view> 
      
      <!-- 菜单-->
      <view class="about-shadow tn-margin-top-xl tn-padding-top-sm tn-padding-bottom-sm tn-margin-left tn-margin-right" v-for="(sublist,index) in ucenterList" :key="index">
        <tn-list-cell :hover="true" :unlined="true" :radius="true" :fontSize="30"  v-for="(item,i) in sublist" @click="ucenterListClick(item)">
          <view class="tn-flex tn-flex-col-center">
            <view :class="['icon1__item--icon tn-flex tn-flex-row-center tn-flex-col-center',item.color,'tn-color-white']" > 
              <view :class="item.icon"></view>
            </view>
            <view class="tn-margin-left-sm tn-flex-1">{{item.title}}</view>
            <view class="tn-margin-left-sm tn-color-cyan tn-icon-right"></view>
          </view>
        </tn-list-cell>
      </view>
    </view>
  </view>
</template>

<script>
  import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
  import NavIndexButton from '@/libs/components/nav-index-button.vue'
  import checkUpdate from '@/uni_modules/uni-upgrade-center-app/utils/check-update';
  import callCheckVersion from '@/uni_modules/uni-upgrade-center-app/utils/call-check-version';
  const pageDataCenter = uniCloud.importObject('page-data-center')
  const db = uniCloud.database();
  import {
  	store,
  	mutations
  } from '@/uni_modules/uni-id-pages/common/store.js'
  export default {
    name: 'about-demo-1',
    mixins: [template_page_mixin],
    components: { NavIndexButton },
	computed: {
		userInfo() {
			return store.userInfo
		},
		hasLogin(){
			return store.hasLogin
		}
	},
    data(){
      return {
		  ucenterList: [[
			  {
			  				  "title": '单词量测试',
			  				  "to": '/pages/test/list',
			  				  "icon": "tn-icon-write-feather",
			  				  "color":"tn-cool-bg-color-1",
			  			  },
			  			  {
			  				  "title": '单词排行榜',
			  				  "to": '/pages/rank/rank',
			  				  "icon": "tn-icon-inventory",
			  				  "color":"tn-cool-bg-color-2",
			  			   },
						   {
								  "title": '我的成就',
								  "to": '/pages/achieve/achieve',
								  "icon": "tn-icon-bookmark",
								  "color":"tn-cool-bg-color-3",
						    }
			  			
		  ],
		  	[
		  	
		  		{
		  			"title": '签到',
		  			"event": 'signIn',
		  			"icon": "tn-icon-logo-tuniao",
					"color":"tn-cool-bg-color-5",
		  		},
		  		{
		  			"title":'浏览记录',
		  			"to": '/pages/ucenter/read-news-log/read-news-log',
		  			"icon": "tn-icon-logo-tuniao",
					"color":"tn-cool-bg-color-8",
		  		},
		  		{
		  			"title": '我的积分',
		  			"to": '',
		  			"event": 'getScore',
		  			"icon": "tn-icon-like-fill",
					"color":"tn-cool-bg-color-6",
		  		}
		  	
		  	],
		  	[{
		  		"title": this.$t('mine.feedback'),
		  		"to": '/uni_modules/uni-feedback/pages/opendb-feedback/opendb-feedback',
		  		"icon": "tn-icon-phone-fill",
				"color":"tn-cool-bg-color-12",
		  	}, {
		  		"title": this.$t('mine.settings'),
		  		"to": '/pages/ucenter/settings/settings',
				"icon": "tn-icon-safe-fill",
		  		"color":"tn-cool-bg-color-4",
		  	}]
		  ],
		  userData:{
			  score:0,
			  days:0,
			  words:0
		  }
      }
    },
	onShow() {
		console.log('this.hasLogin',this.hasLogin)
		this.hasLogin && pageDataCenter.getUserData().then((res)=>{
			console.log('getUserData',res)
			if(res.code){
				this.userData=res.data
			}
		})
	},
    methods: {
		toSettings() {
			uni.navigateTo({
				url: "/pages/ucenter/settings/settings"
			})
		},
		signIn() { //普通签到
			this.$refs.signIn.open()
		},
		signInByAd(){ //看激励视频广告签到
			this.$refs.signIn.showRewardedVideoAd()
		},
		toUserInfo() {
			uni.navigateTo({
				url: '/uni_modules/uni-id-pages/pages/userinfo/userinfo'
			})
		},
		tapGrid(index) {
			uni.showToast({
				// title: '你点击了，第' + (index + 1) + '个',
				title: this.$t('mine.clicked') + " " + (index + 1) ,
				icon: 'none'
			});
		},
		/**
		 * 获取积分信息
		 */
		getScore() {
			if (!this.userInfo) return uni.showToast({
				title: this.$t('mine.checkScore'),
				icon: 'none'
			});
			uni.showLoading({
				mask: true
			})
			db.collection("uni-id-scores")
				.where('"user_id" == $env.uid')
				.field('score,balance')
				.orderBy("create_date", "desc")
				.limit(1)
				.get()
				.then((res) => {
					console.log(res);
					const data = res.result.data[0];
					let msg = '';
					msg = data ? (this.$t('mine.currentScore')+ data.balance) : this.$t('mine.noScore');
					uni.showToast({
						title: msg,
						icon: 'none'
					});
				}).finally(()=>{
					uni.hideLoading()
				})
		},
		/**
		 * 个人中心项目列表点击事件
		 */
		ucenterListClick(item) {
			if(item.to){
				uni.navigateTo({
					url:item.to
				})
				return
			}
			if (item.event) {
				this[item.event]();
			}
		},
    }
  }
</script>

<style lang="scss" scoped>
  @import '@/static/css/templatePage/custom_nav_bar.scss';
  .template-about{
  }
  /* 顶部背景图 start */
  .top-backgroup {
    height: 450rpx;
    z-index: -1;
  
    .backgroud-image {
      width: 100%;
      height: 450rpx;
      // z-index: -1;
    }
  }
  /* 顶部背景图 end */
  
  /* 波浪*/
  @keyframes move_wave {
      0% {
          transform: translateX(0) translateZ(0) scaleY(1)
      }
      50% {
          transform: translateX(-25%) translateZ(0) scaleY(1)
      }
      100% {
          transform: translateX(-50%) translateZ(0) scaleY(1)
      }
  }
  .tnwave {
      overflow: hidden;
      position: absolute;
      z-index: 9;
      height: 200rpx;
      left: 0;
      right: 0;
      top: 290rpx;
      bottom: auto;
  }
  .waveWrapperInner {
      position: absolute;
      width: 100%;
      overflow: hidden;
      height: 100%;
  }
  .wave {
      position: absolute;
      left: 0;
      width: 200%;
      height: 100%;
      background-repeat: repeat no-repeat;
      background-position: 0 bottom;
      transform-origin: center bottom;
  }
  
  .bgTop {
      opacity: 0.4;
  }
  .waveTop {
      background-size: 50% 45px;
  }
  .waveAnimation .waveTop {
    animation: move_wave 4s linear infinite;
  }
  
  .bgMiddle {
      opacity: 0.6;
  }
  .waveMiddle {
      background-size: 50% 40px;
  }
  .waveAnimation .waveMiddle {
      animation: move_wave 3.5s linear infinite;
  }
  
  .bgBottom {
      opacity: 0.95;
  }
  .waveBottom {
      background-size: 50% 35px;
  }
  .waveAnimation .waveBottom {
      animation: move_wave 2s linear infinite;
  }
  /* 波浪*/
  
  /* 页面 start*/
  .about-shadow{
    border-radius: 15rpx;
    box-shadow: 0rpx 0rpx 50rpx 0rpx rgba(0, 0, 0, 0.07);
  }
  
  .about {
    
    &__wrap {
      position: relative;
      z-index: 1;
      // margin: 20rpx 30rpx;
      margin-top: -330rpx;
    }
  }
  /* 页面 end*/
  
  /* 用户信息 start */
  .user-info {
    &__container {
      
    }
    
    &__avatar {
      width: 170rpx;
      height: 170rpx;
      border: 8rpx solid rgba(255,255,255,0.05);
      border-radius: 50%;
      overflow: hidden;
      box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.15);
    }
    
    &__nick-name {
      margin-top: 26rpx;
      font-size: 36rpx;
      font-weight: 600;
      text-align: center;
    }
  }
  /* 用户信息 end */
  /* 图标容器1 start */
  .icon1 {
    &__item {
      // width: 30%;
      background-color: #FFFFFF;
      border-radius: 10rpx;
      padding: 30rpx;
      margin: 20rpx 10rpx;
      transform: scale(1);
      transition: transform 0.3s linear;
      transform-origin: center center;
      
      &--icon {
        width: 40rpx;
        height: 40rpx;
        font-size: 28rpx;
        border-radius: 50%;
        position: relative;
        z-index: 1;
        
        &::after {
          content: " ";
          position: absolute;
          z-index: -1;
          width: 100%;
          height: 100%;
          left: 0;
          bottom: 0;
          border-radius: inherit;
          opacity: 1;
          transform: scale(1, 1);
          background-size: 100% 100%;
          background-image: url(https://resource.tuniaokj.com/images/cool_bg_image/icon_bg.png);
        }
      }
    }
  }
    /* 图标容器1 end */
    
    /* 底部tabbar start*/
    .footerfixed{
     position: fixed;
     width: 100%;
     bottom: 0;
     z-index: 999;
     background-color: #FFFFFF;
     box-shadow: 0rpx 0rpx 30rpx 0rpx rgba(0, 0, 0, 0.07);
    }
    
    .tabbar {
      display: flex;
      align-items: center;
      min-height: 110rpx;
      justify-content: space-between;
    	padding: 0;
    	height: calc(110rpx + env(safe-area-inset-bottom) / 2);
    	padding-bottom: calc(env(safe-area-inset-bottom) / 2);
    }
    
    .tabbar .action {
    	font-size: 22rpx;
    	position: relative;
    	flex: 1;
    	text-align: center;
    	padding: 0;
    	display: block;
    	height: auto;
    	line-height: 1;
    	margin: 0;
    	overflow: initial;
    }
    
    .tabbar .action .bar-icon {
    	width: 100rpx;
    	position: relative;
    	display: block;
    	height: auto;
    	margin: 0 auto 10rpx;
    	text-align: center;
    	font-size: 42rpx;
    }
    
    .tabbar .action .bar-icon image {
    	width: 50rpx;
    	height: 50rpx;
    	display: inline-block;
    }
</style>
